package yja.gzw.app.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.CheckBox
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.kongzue.dialogx.dialogs.CustomDialog
import com.kongzue.dialogx.interfaces.OnBindView
import yja.gzw.app.R
import yja.gzw.app.adapter.DiminAdapter.OnItemClickListener
import yja.gzw.app.model.bean.RechargeInfokaipiao

class KaipiaoAdapter (private val context: Context, private val list: List<RechargeInfokaipiao>,val isis:Boolean,private val listener:OnItemClickListener):
    RecyclerView.Adapter<RecyclerView.ViewHolder>(){
    interface OnItemClickListener {
        fun onItemClick22(position: Int,isi:Boolean,list: List<RechargeInfokaipiao>)
    }

        private var view: View?=null
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        view= LayoutInflater.from(parent.context).inflate(R.layout.item_kaipiao,parent,false)
        return ViewHodeView(view!!)
    }

    override fun getItemCount(): Int {
        return list.size
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        if(holder is ViewHodeView){
            holder.name.text=list[position].title
            holder.shijian.text="充值时间："+list[position].ceratetime
            holder.qian.text="￥"+list[position].price

            if(list[position].status==2){
                holder.chankan.visibility=View.VISIBLE

            }

            if(list[position].status==0){

                holder.xuan.visibility=View.VISIBLE
            }

            holder.xuan.isChecked= list[position].isisss


            holder.xuan.setOnClickListener {

                if(holder.xuan.isChecked){

                    holder.xuan.isChecked=true
                    list[position].isisss=true

                }else{

                    list[position].isisss=false
                    holder.xuan.isChecked=false
                }
              //  notifyItemChanged(position)
                notifyDataSetChanged()
                listener.onItemClick22(position,list[position].isisss,list)
            }


        holder.chankan.setOnClickListener {

            CustomDialog.show(object : OnBindView<CustomDialog>(R.layout.layout_custom_tupian) {
                override fun onBind(dialog: CustomDialog, v: View) {

                        Glide.with(context).load("http://117ai.32.hzgqapp.com/"+list[position].url).into(v.findViewById(R.id.tupian))

                }
            })
                .setMaskColor(context.getColor(R.color.touming))

        }




        }
    }
    inner class ViewHodeView(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val name: TextView =itemView.findViewById(R.id.name)
        val shijian: TextView =itemView.findViewById(R.id.shijian)
        val qian: TextView =itemView.findViewById(R.id.qian)
        val xuan: CheckBox =itemView.findViewById(R.id.xuan)
        var chankan:TextView=itemView.findViewById(R.id.chankan)
    }



}